package com.zpxt.zpxt.serve;

import com.zpxt.zpxt.dao.CompanyRepository;
import com.zpxt.zpxt.dao.TalentRepository;
import com.zpxt.zpxt.entity.Company;
import com.zpxt.zpxt.entity.Talent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author:hjx
 * @Description:
 * @Date: Created in 15:19 2018/4/11
 * @Modified By:
 */
@Service("loginServe")
public class LoginServe {
    @Autowired
    CompanyRepository companyRepository;
    @Autowired
    TalentRepository talentRepository;

    public Company companyLogin(String code,String password) throws Exception {
        List<Company> list = companyRepository.findByCode(code);
        if (list.size() == 0){
            throw new Exception("企业账号不存在！");
        }else {
            Company company =list.get(0);
            String pass = company.getPassword();
            if (!pass.equals(password)){
                throw new Exception("密码错误！");
            }
            return  company;
        }
    }

    public Talent talentLogin(String code,String password) throws Exception {
        List<Talent> list = talentRepository.findByCode(code);
        if (list.size() == 0){
            throw new Exception("求职者账号不存在！");
        }else {
            Talent talent =list.get(0);
            String pass = talent.getPassword();
            if (!pass.equals(password)){
                throw new Exception("密码错误！");
            }
            return talent;
        }
    }
}
